Define typed domain errors with codes and messages, wrap errors with context at each layer boundary, map to HTTP/gRPC status codes in middleware, and log with full structured context.
Layer errors: domain layer returns domain errors, service layer wraps with context, transport layer maps to protocol codes
Wrap at boundaries: fmt.Errorf("operation: %w", err) to build traceable error chains
Never expose internal errors (DB errors, stack traces) to external API clients
Attach structured context to logs: error code, request ID, user ID, operation name
Define sentinel errors for expected cases (ErrNotFound, ErrConflict) and typed errors for recoverable cases with extra data